package config

import (
	"gopkg.in/yaml.v3"
	"log"
	"os"
)

var _config *Config

// Init 初始化配置
func Init() *Config {
	yamlFile, err := os.ReadFile("./config/config.yml")
	if err != nil {
		return nil
	}
	// 解析YAML内容到Config结构体
	var config Config
	err = yaml.Unmarshal(yamlFile, &config)
	if err != nil {
		log.Fatalf("Failed to parse YAML file: %v", err)
	}
	_config = &config
	return &config
}

// GetBoyGoConfig 获取BoyGo配置
func GetBoyGoConfig() BoyGoConfig {
	if _config == nil {
		return BoyGoConfig{
			Name:           "BoyGo",
			Version:        "1.0.0",
			Profile:        "dev",
			CopyrightYear:  "2025",
			AddressEnabled: true,
			CaptchaType:    "math", // 验证码方式【数学】
		}
	}
	return _config.BoyGo
}

// GetTokenConfig 获取Token配置
func GetTokenConfig() TokenConfig {
	if _config == nil {
		return TokenConfig{
			Header:     "Authorization",
			Secret:     "topqrsxwmnyzedcbafguvhijkl",
			ExpireTime: 30,
		}
	}
	return _config.Token
}
